// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.asm;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.MethodNode;

import com.dustedpixels.asm.tree.TreeUtils;


/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class AnalysisUtilsTest {
  public static void main(String[] args) throws Exception {
    testOne();
  }
  
  public static void testOne() throws Exception {
    String className = "Foo"; 
    MethodNode method = new MethodNode(0, "foo", "(IJI)I", null, new String[0]);
    method.visitCode();
    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitVarInsn(Opcodes.ILOAD, 1);
    method.visitVarInsn(Opcodes.LLOAD, 2);
    method.visitVarInsn(Opcodes.ILOAD, 4);
    method.visitVarInsn(Opcodes.ISTORE, 1);
    method.visitVarInsn(Opcodes.LSTORE, 2);
    method.visitInsn(Opcodes.POP);
    method.visitInsn(Opcodes.POP);
    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(4, 5);
    method.visitEnd();
    
    TreeUtils.printTrace(method);
    
    boolean[][] localsUsage = AnalysisUtils.analyseLocalsUsage(className, method);
    for (int insnIndex = 0; insnIndex < localsUsage.length; insnIndex++) {
      System.out.print(insnIndex + ":\t");
      for (int localIndex = 0; localIndex < localsUsage[insnIndex].length; localIndex++) {
        System.out.print(localsUsage[insnIndex][localIndex] ? "X" : "-");
      }
      System.out.println();
    }
  }
}
